package tools;

import java.io.File;
import java.io.IOException;

import javax.per.toolkit.file.FileUtil;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class Env {
	
	private static String prefix="";
	private static String[] envtype=new String[]{"co","ho","ub",""};
	
	static{
		for(String s:envtype){
			prefix=s;
			if(new File(get("desktop")).exists()){
				break;
			}
		}
		if(prefix.equals("")){
			throw new Error();
		}
		//Log.getLogger().debug("Env "+prefix);
	}
	
	public static String get(String name){
		try {
			String content=FileUtil.getContent(Env.class.getResource("env.xml"));
			Document doc=Jsoup.parse(content);
			Elements eles=doc.getElementById("root").children();
			for(Element ele:eles){
				if(ele.attr("prefix").equalsIgnoreCase(prefix)&&ele.attr("name").equalsIgnoreCase(name)){
					return ele.attr("value").trim();
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static String getEnv(){
		return prefix.toLowerCase().trim();
	}

}
